package routes

import (
	"github.com/gin-gonic/gin"
	"lottery/bootstrap"
	"lottery/services"
	"lottery/web/controllers"
)

func ConfigGetRoutes(app *bootstrap.Bootstrapper) {
	// 初始化 各种数据操作对象
	userService := services.NewUserService()
	giftService := services.NewGiftService()
	codeService := services.NewCodeService()
	resultService := services.NewResultService()
	userdayService := services.NewUserdayService()
	blackipService := services.NewBlackipService()

	// 初始化 index：IndexController 等各类控制器
	Index := controllers.IndexController{ServiceGift: giftService, ServiceUserday: userdayService, ServiceBlackip: blackipService, ServiceUser: userService, ServiceResult: resultService, ServiceCode: codeService}
	Admin := controllers.AdminController{ServiceGift: giftService}
	AdminGift := controllers.AdminGiftController{ServiceGift: giftService}
	AdminCode := controllers.AdminCodeController{ServiceGift: giftService, ServiceCode: codeService}
	AdminResult := controllers.AdminResultController{ServiceGift: giftService, ServiceCode: codeService, ServiceResult: resultService}
	AdminUser := controllers.AdminUserController{ServiceUser: userService}
	AdminBlackip := controllers.AdminBlackipController{ServiceBlackip: blackipService}

	// 指定路由，加载路由
	// 1. 网站首页
	v1 := app.Group("/")
	addIndexRouters(v1, &Index)

	// 2. admin 后台管理路由
	v2 := app.Group("/admin")
	// 启用中间件: BasicAuth()（验证）中间件
	v2.Use(gin.BasicAuth(gin.Accounts{
		"admin": "123456", // 添加一个管理员用户
	}))
	addAdminRouters(v2, &Admin)

	// 3. 奖品管理页
	v3 := v2.Group("/gift")
	addAdminGiftRouters(v3, &AdminGift)

	// 4. 优惠券管理页
	v4 := v2.Group("/code")
	addAdminCodeRouters(v4, &AdminCode)

	// 5. 中奖结果管理
	v5 := v2.Group("/result")
	addAdminResultRouters(v5, &AdminResult)

	// 6. 用户管理
	v6 := v2.Group("/user")
	addAdminUserRouters(v6, &AdminUser)

	// 7. ip 黑名单管理
	v7 := v2.Group("/blackip")
	addAdminBlackipRouters(v7, &AdminBlackip)
}
